package com.smart.controller;

import com.smart.entity.EnvironmentThresholds;
import com.smart.entity.Result;
import com.smart.service.IEnvironmentThresholdsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 环境数据阈值表 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-05-28
 */
@RestController
@CrossOrigin
@RequestMapping("/thresholds")
@Api(tags = "环境数据阈值相关接口")
public class EnvironmentThresholdsController {
    @Autowired
    private IEnvironmentThresholdsService environmentThresholdsService;

    @GetMapping("/{type}")
    @ApiOperation(value = "获取环境数据阈值", response = Result.class)
    public Result getEnvironmentThresholdsByType(
            @PathVariable @ApiParam(name = "环境类型", required = true) String type) {
        return Result.success(environmentThresholdsService.getEnvironmentThresholdsByType(type));
    }

    @PutMapping
    @ApiOperation(value = "更新环境数据阈值", response = Result.class)
    public Result updateEnvironmentThresholds(
            @RequestBody @ApiParam(name = "环境数据阈值", required = true) EnvironmentThresholds environmentThresholds) {
        boolean isSucceed = environmentThresholdsService.updateById(environmentThresholds);
        return isSucceed ? Result.success() : Result.error("系统繁忙，请稍后再试");
    }
}
